/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package database.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Stefan
 */
@Entity
@Table(name = "shopping_cart")
@NamedQueries({
    @NamedQuery(name = "ShoppingCart.findAll", query = "SELECT s FROM ShoppingCart s"),
    @NamedQuery(name = "ShoppingCart.findByCartid", query = "SELECT s FROM ShoppingCart s WHERE s.cartid = :cartid"),
    @NamedQuery(name = "ShoppingCart.findByCartdate", query = "SELECT s FROM ShoppingCart s WHERE s.cartdate = :cartdate"),
    @NamedQuery(name = "ShoppingCart.findByCartdiscarted", query = "SELECT s FROM ShoppingCart s WHERE s.cartdiscarted = :cartdiscarted"),
    @NamedQuery(name = "ShoppingCart.findByCartactive", query = "SELECT s FROM ShoppingCart s WHERE s.cartactive = :cartactive")})
public class ShoppingCart implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "CARTID")
    private Integer cartid;
    @Basic(optional = false)
    @Column(name = "CARTDATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date cartdate;
    @Basic(optional = false)
    @Column(name = "CARTDISCARTED")
    private boolean cartdiscarted;
    @Basic(optional = false)
    @Column(name = "CARTACTIVE")
    private boolean cartactive;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "shoppingCart", fetch = FetchType.LAZY)
    private List<CartItem> cartItemList;
    @JoinColumn(name = "USERID", referencedColumnName = "USERID")
    @ManyToOne(fetch = FetchType.LAZY)
    private User user;

    public ShoppingCart() {
    }

    public ShoppingCart(Integer cartid) {
        this.cartid = cartid;
    }

    public ShoppingCart(Integer cartid, Date cartdate, boolean cartdiscarted, boolean cartactive) {
        this.cartid = cartid;
        this.cartdate = cartdate;
        this.cartdiscarted = cartdiscarted;
        this.cartactive = cartactive;
    }

    public Integer getCartid() {
        return cartid;
    }

    public void setCartid(Integer cartid) {
        this.cartid = cartid;
    }

    public Date getCartdate() {
        return cartdate;
    }

    public void setCartdate(Date cartdate) {
        this.cartdate = cartdate;
    }

    public boolean getCartdiscarted() {
        return cartdiscarted;
    }

    public void setCartdiscarted(boolean cartdiscarted) {
        this.cartdiscarted = cartdiscarted;
    }

    public boolean getCartactive() {
        return cartactive;
    }

    public void setCartactive(boolean cartactive) {
        this.cartactive = cartactive;
    }

    public List<CartItem> getCartItemList() {
        return cartItemList;
    }

    public void setCartItemList(List<CartItem> cartItemList) {
        this.cartItemList = cartItemList;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cartid != null ? cartid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ShoppingCart)) {
            return false;
        }
        ShoppingCart other = (ShoppingCart) object;
        if ((this.cartid == null && other.cartid != null) || (this.cartid != null && !this.cartid.equals(other.cartid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "database.entity.ShoppingCart[cartid=" + cartid + "]";
    }

}
